<template>

    <commonformdialog
      :isshowDialogs="isshowDialog"
      :isshowconfirmbtn="false"
      :dialogWidth="'40%'"
      :enterTitle="false"
      :isshowimportTitle="false"
      :dialogTitle="'设置'"
      @closetextDialog="closetextDialog"
      @confirmbtn="confirmbtn"
      :topHeight="'25vh'"
    >
      <div class="innerloding">
        <el-form
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="100px"
      >
      <el-row>
        <el-col :span="24">
          <el-form-item label-width="0">
            <el-checkbox-group v-model="checkList">
          <el-checkbox :label="1">套餐包剩余不足 <el-input-number controls-position="right" v-model="formData.notice" :min='1' :max="9999" :disabled='checkList.indexOf(1)==-1' style="width:100px;margin:0 10px"></el-input-number> 人次时发出警告</el-checkbox>
          <el-checkbox :label="2">套餐包剩余不足 <el-input-number  controls-position="right" v-model="formData.surplus" :min='1' :max="9999" :disabled='checkList.indexOf(2)==-1'  style="width:100px;margin:0 10px"></el-input-number > 人次时自动续订 <el-input-number controls-position="right"  v-model="formData.total" :min='1' :max="9999" :disabled='checkList.indexOf(2)==-1' style="width:100px;margin:0 10px"></el-input-number > 人次</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        </el-col>
      </el-row>
        
      </el-form>
      </div>
    </commonformdialog>

</template>

<script>
//引入弹窗
import commonformdialog from '@/components/commondialog/commondialog'
import { getSessionStorage } from '@/utils/accessToken'
//api
import {
packageSetting
} from '@/api/activity'
export default {
  data() {
    return {
      //表单数据
      checkList:[],
      formData: {

      },
      rules: {
      },
    }
  },
  components: {
    commonformdialog,
  },
  props: {
    //是否显示弹窗
    isshowDialog: {
      type: Boolean,
      default: false,
    },
    //点击传递的参数
    dialogparams: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  methods: {
    //关闭弹窗
    closetextDialog() {
      this.$refs['elForm'].resetFields()
      this.$emit('closedefer')
    },
    //点击确认
    async confirmbtn() {
      console.log(this.checkList)
      let {notice,surplus,total}=this.formData
      let params={notice,surplus,total}
      if(this.checkList.length==0){
        params.status=0
      }else if(this.checkList.length==2){
         params.status=3
      }else{
        params.status=this.checkList[0]
      }
      let data=await packageSetting(params)
      if(data.code=='0000'){
        this.$message({
          type: 'success',
          message: data.msg
        })
         this.$emit('confirm')
      }
    },
  },
  watch: {
    dialogparams(val) {
     if(val){
       this.formData=Object.assign({},val);
     }
    },
    "formData.status":function(val){
      if (val==0){
        this.checkList=[]
      }else if(val==3){
         this.checkList=[1,2]
      }else{
        this.checkList[0]=val
      }
    
    },

  },
  mounted() {

  },
}
</script>

<style scoped lang='scss'>
::v-deep{
  .el-input-number__increase{
    display: none;
  }
  .el-input-number__decrease{
       display: none;
  }
}
</style>
